package lib.bone.system.dao;

import lib.bone.system.domain.entity.SysDept;
import lib.bone.system.domain.vo.SysDeptBasic;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Optional;

public interface SysDeptDAO extends JpaRepository<SysDept,Long>, JpaSpecificationExecutor<SysDept> {
    /**
     * 根据ID删除
     */
    void deleteById(String deptId);
    /**
     * 根据ID列表删除
     */
    void deleteByIdIn(List<Long> idList);
    /**
     * 根据ID列表查询
     */
    List<SysDept> findByIdIn(List<Long> ids);

    Optional<SysDept> findByDeptName(String deptName);

    Optional<SysDept> findById(String deptId);





    /**
     * 根据父ID进行查询
     */
    @Query(value = "SELECT * FROM sys_dept WHERE parent_id = ?1", nativeQuery = true)
    List<SysDept> findByParentId(Long parentId);

    /** 父部门为空查询 **/
    List<SysDept> findByParentIsNull();


    @Query("select new lib.bone.system.domain.vo.SysDeptBasic(t.id, t.deptName) from SysDept t")
    List<SysDeptBasic> getAllDeptBasic();
}
